import { CodeGenerateField } from "@/types/admin/codeGenerate";
import { model, Schema } from "mongoose";

const CodeGenerateFieldSchema = new Schema<CodeGenerateField>(
    {
        name: { type: String, required: true },
        label: { type: String },
        type: {
            type: String,
            enum: ["Number", "String", "Boolean", "ObjectId", "Object", "NumberArray", "StringArray", "BooleanArray", "ObjectIdArray", "ObjectArray"],
            default: "String",
        },
        componentType: { type: String, enum: ["textarea", "inputNumber", "radio", "select", "input", "autoComplete"] },
        isTable: { type: Boolean, default: true },
        isForm: { type: Boolean, default: true },
        queryType: { type: String, enum: ["fuzzy", "precise"] },
        required: { type: Boolean, default: false },
        unique: { type: Boolean, default: false },
        sortType: { type: String, enum: ["asc", "desc"] },
        dictType: String,
    },
    { timestamps: { createdAt: true, updatedAt: true } }
);

export const CodeGenerateFieldModel = model("CodeGenerateField", CodeGenerateFieldSchema);
